package com.example.baseapp.admin.controller;

import com.example.baseapp.admin.dto.resp.RoleResp;
import com.example.baseapp.admin.entity.Role;
import com.example.baseapp.admin.service.RoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * RoleController class
 *
 * @author zhangl
 * @date 2022/4/28 14:36
 */
@RestController
@RequestMapping("admin")
public class RoleController {
    @Resource
    private RoleService roleService;
    @GetMapping("roles")
    public List<RoleResp> getAllRole(){
        List<Role> roleList =  roleService.queryById();
        List<RoleResp> roleRespList = null;
        if (!CollectionUtils.isEmpty(roleList)){
            roleRespList = roleList.stream().map(role -> {
                RoleResp roleResp = new RoleResp();
                BeanUtils.copyProperties(role,roleResp);
                return roleResp;
            }).collect(Collectors.toList());
        }
        return roleRespList ;
    }
}
